home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / database / postgres / appgen-0.2-a / appgen-0 / AppGEN / src / java / graph.java < prev    next >
Encoding:
Java Source  |  1996-07-10  |  2.1 KB  |  90 lines

  1.  
  2. import java.applet.Applet;
  3. import java.awt.Graphics;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.lang.System;
  7.  
  8.  
  9. public class graph extends Applet {
  10.     int AppletHeight, AppletWidth;
  11.     int rows;
  12.     float[] y = new float[64];
  13.     String[] x = new String[64];
  14.     String type;
  15.     float yscale;
  16.     float xscale;
  17.     int ten;
  18.  
  19.     public void init() {
  20.         int a;
  21.         String xp;
  22.         String yp;
  23.         Dimension d = size();        
  24.         AppletHeight = d.height;
  25.         AppletWidth = d.width;
  26.         type=getParameter("type");
  27.         rows=Integer.valueOf(getParameter("rows")).intValue();    
  28.         for (a=1; a<=rows; a++) {
  29.             xp="x" + String.valueOf(a);
  30.             yp="y" + String.valueOf(a);        
  31.             y[a]=Float.valueOf(getParameter(yp)).floatValue();
  32.             x[a]=getParameter(xp);
  33.             }
  34.         }
  35.         
  36.     public void paint(Graphics g) {
  37.         border(g,AppletHeight,AppletWidth);
  38.         axis(g);
  39.         chart_bar(g);
  40.         axis(g);
  41.         }
  42.  
  43.     public void border(Graphics g, int AppletHeight, int AppletWidth) {
  44.         g.setColor(Color.white);
  45.         g.fillRect(0,0,AppletWidth-1,AppletHeight-1);
  46.         g.setColor(Color.black);
  47.         g.drawRect(2,2,AppletWidth-5,AppletHeight-5);
  48.         }
  49.  
  50.     public void axis(Graphics g) {
  51.         float upper = 0;
  52.         float lower = 0;
  53.         float yrange;
  54.         int a;
  55.         ten = AppletWidth / 10;
  56.         for (a=1; a<=rows; a++) {
  57.             if ( y[a] > upper ) upper = y[a];
  58.             if ( y[a] < lower ) lower = y[a];
  59.             }
  60.         yrange = upper - lower;
  61.         yscale = (AppletHeight-(ten*2)) / yrange;
  62.         xscale = (AppletWidth-ten) / rows;
  63.         g.setColor(Color.black);
  64.         g.drawLine(ten/2,AppletHeight-ten,ten/2,ten/2);
  65.         g.drawLine(AppletWidth-ten,AppletHeight-ten,ten/2,AppletHeight-ten);
  66.         g.drawLine((ten/2)-1,AppletHeight-ten,(ten/2)-1,ten/2);
  67.         g.drawLine(AppletWidth-ten,AppletHeight-ten-1,ten/2,AppletHeight-ten-1);
  68.     
  69.         }  
  70.  
  71.     public void chart_bar(Graphics g) {
  72.         int a;
  73.         int x1,x2,y1,y2;
  74.         Color c = Color.blue;
  75.         for (a=1; a<=rows; a++) {
  76.             g.setColor(c);
  77.             x1=(int) (ten/2 + (xscale * (a-1)));
  78.             y1=(int) ((AppletHeight-ten) - (yscale * y[a]));
  79.             x2=(int) xscale-(ten/2);
  80.             y2=(int) (yscale * y[a]);
  81.             g.fillRect(x1,y1,x2,y2);
  82.             g.setColor(Color.black);
  83.             g.drawString(x[a],x1+(ten/3),AppletHeight-(ten/2));
  84.             g.drawString(Float.toString(y[a]),x1+(ten/3),y1-(ten/3));
  85.             }
  86.     
  87.         }    
  88. }
  89.  
  90.